<template>
  <div>
<!--    <div class="account-title">-->
<!--      账户设置-->
<!--    </div>-->
    <van-nav-bar
      title="账户设置"
      left-text="返回"
      left-arrow
      @click-left="onClickLeft"
    />
<!--    显示下半部分-->
    <div class="tab_home_account">
      <!--    显示用户名-->
      <div class="account-content">
        <span class="account-phone">手机号码</span>
        <span class="phone">{{nick_name}}</span>
      </div>
      <div class="account-button">
        <van-button
          size="large"
          type="primary"
          :loading="isLogining"
          @click="logout"
        >退出当前账号
        </van-button>
      </div>
      </van-cell-group>
    </div>
  </div>
</template>

<script>
import avatarDefault from '../../../assets/images/avatar_default.png'
import { Field, CellGroup, Button, NavBar  } from 'vant'
import { getLocalStorage } from '../../../common/utils/local-storage'
export default {
  components: {
    [Field.name]: Field,
    [CellGroup.name]: CellGroup,
    [Button.name]: Button,
    [NavBar.name]: NavBar
  },
  data () {
    return {
      isLogin: false,
      nick_name: '昵称',
      avatar: avatarDefault,
    }
  },
  mounted () {
    this.getUserInfo()
  },
  methods: {
    // 返回上一页的方法
    onClickLeft () {
      this.$router.go(-1)
    },
    getUserInfo () {
      const infoData = getLocalStorage(
        'username',
        'wechat_nick_name',
        'wechat_avatar',
        'token'
      )
      console.log(infoData)
      this.nick_name = infoData.wechat_nick_name || infoData.username || '昵称'
      this.avatar = infoData.wechat_avatar || avatarDefault
      if (infoData.token !== null) {
        this.isLogin = true
      }
    },
    logout () {
      this.$store.commit('logout')
      this.$router.push({ name: 'tab-home'})
      this.$router.go ()
    }
  }
}
</script>

<style scoped lang="less">
  /*.tab_home_account{*/
  /*  background-color: #cccccc;*/
  /*}*/
.account-title{
  position: relative;
  text-align: center;
  width: 100%;
  /*height: 20%;*/
  height: 30%;
  padding-top: 10px;
  padding-bottom: 10px;
  font-weight: 600;
  font-size: large;
}
.tab_home_account{
  height: 70%;
  width: 100%;
}
.account-content{
  margin-top: 15px;
  box-shadow: 0 0.1875rem 1.25rem #e2e6e5;
  background-color: white;
  height: 30%;
  padding: 15px 0 15px 0;
  font-size: 15px;
  .account-phone{
    padding-left: 20px;
    font-weight: 550;

  }
  .phone{
    color: #969799;
    font-size: 13px;
    float: right;
    padding-right: 20px;
  }
}
.account-button{
  margin: 30px 10px 0 10px;
}
</style>
